const path = require('path');

// 本地反向代理
const proxyTable = require('./config/proxyTable.js');
// 项目依赖图显示
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
    .BundleAnalyzerPlugin;
// lodash 按需加载
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');

const resolve = (dir) => {
    return path.join(__dirname, dir);
};

let plugins = [new LodashModuleReplacementPlugin()];
if (process.env.NODE_ENV == 'production') {
    plugins = plugins.concat([
        // new LodashModuleReplacementPlugin(),
        new BundleAnalyzerPlugin({
            analyzerMode: 'static',
            reportFilename: './log/main-report.html',
        }),
    ]);
}

module.exports = {
    publicPath: '/',
    css: {
        requireModuleExtension: true,
        loaderOptions: {
            less: {
                module: true,
            },
        },
    },
    configureWebpack: {
        resolve: {
            alias: {
                '@': resolve('src'),
                utils: resolve('src/utils'),
                styles: resolve('src/styles'),
            },
        },
        plugins,
    },
    productionSourceMap: false,
    devServer: {
        // https: true,
        proxy: proxyTable,
    },
};
